<template>
  <div>
    <table id="pdf" v-if="loading">
      <colgroup>
        <col width="300"/>
        <col width="250"/>
        <col width="450"/>
        <col width="60"/>
        <col width="100"/>
      </colgroup>
      <tbody>
      <tr class="firstRow">
        <td colspan="2">姓名</td>
        <td colspan="3">学号</td>
      </tr>
      <tr>
        <td colspan="2">{{ this.userName }}</td>
        <td colspan="3">{{this.accountNo}}</td>
      </tr>
      <tr>
        <td>类别</td>
        <td>项目类别</td>
        <td>项目名称</td>
        <td>分数</td>
        <td>总分</td>
      </tr>

      <tr v-if="!messageObject['20240327141803'] || messageObject['20240327141803'].length === 0">
        <td :rowspan="calculateRowspan(['20240327141803', '20240327141805', '20240327141807', '20240327141809'])">思想品德（A1）<br/>A1=基础分+加分项-减分项</td>
        <td>政治素养加分项</td>
        <td>无数据</td>
        <td>0</td>
        <td :rowspan="calculateRowspan(['20240327141803', '20240327141805', '20240327141807', '20240327141809'])">{{ totalA1 }} <br/> (基础30)</td>
      </tr>
      <tr v-else>
        <td :rowspan="calculateRowspan(['20240327141803', '20240327141805', '20240327141807', '20240327141809'])">思想品德（A1）<br/>A1=基础分+加分项-减分项</td>
        <td :rowspan="this.messageObject['20240327141803'].length || 1">政治素养加分项</td>

        <td v-if="this.messageObject['20240327141803'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141803'][0].photoUrl)">{{ this.messageObject["20240327141803"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141803"][0].name }}</td>
        <td>{{this.messageObject["20240327141803"][0].score}}</td> <!-- 只打印第一个元素 -->
        <td :rowspan="calculateRowspan(['20240327141803', '20240327141805', '20240327141807', '20240327141809'])">{{ totalA1 }} <br/> (基础30)</td>
      </tr>
      <tr v-if="messageObject['20240327141803'].length > 1" v-for="(award, index) in messageObject['20240327141803'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>

      <!-- 政治素养减分项 -->
      <tr v-if="!messageObject['20240327141805'] || messageObject['20240327141805'].length === 0">
        <td>政治素养减分项</td>
        <td>无数据</td>
        <td>0</td>
      </tr>
      <tr v-else>
        <td :rowspan="this.messageObject['20240327141805'].length || 1">政治素养减分项</td>
        <td v-if="this.messageObject['20240327141805'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141805'][0].photoUrl)">
          {{ this.messageObject["20240327141805"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141805"][0].name }}</td>
        <td>{{this.messageObject["20240327141805"][0].score}}</td> <!-- 只打印第一个元素 -->
      </tr>
      <tr v-if="messageObject['20240327141805'].length > 1" v-for="(award, index) in messageObject['20240327141805'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>

      <!-- 行为规范加分项 -->
      <tr v-if="!messageObject['20240327141807'] || messageObject['20240327141807'].length === 0">
        <td>行为规范加分项</td>
        <td>无数据</td>
        <td>0</td>
      </tr>
      <tr v-else>
        <td :rowspan="this.messageObject['20240327141807'].length || 1">行为规范加分项</td>
        <td v-if="this.messageObject['20240327141807'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141807'][0].photoUrl)">
          {{ this.messageObject["20240327141807"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141807"][0].name }}</td>
        <td>{{this.messageObject["20240327141807"][0].score}}</td> <!-- 只打印第一个元素 -->
      </tr>
      <tr v-if="messageObject['20240327141807'].length > 1" v-for="(award, index) in messageObject['20240327141807'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>

      <tr v-if="!messageObject['20240327141809'] || messageObject['20240327141809'].length === 0">
        <td>行为规范减分项</td>
        <td>无数据</td>
        <td>0</td>
      </tr>
      <tr v-else>
        <td :rowspan="this.messageObject['20240327141809'].length || 1">行为规范减分项</td>
        <td v-if="this.messageObject['20240327141809'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141809'][0].photoUrl)">
          {{ this.messageObject["20240327141809"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141809"][0].name }}</td>
        <td>{{this.messageObject["20240327141809"][0].score}}</td> <!-- 只打印第一个元素 -->
      </tr>
      <tr v-if="messageObject['20240327141809'].length > 1" v-for="(award, index) in messageObject['20240327141809'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>

      <tr v-if="this.messageObject['20240327141811'].length === 0">
        <td :rowspan="calculateRowspan(['20240327141811'])">学业成绩（A2）<br/> A2=(平均绩点+5)*10</td>
        <td>学业成绩</td>
        <td>平均绩点</td>
        <td>无数据</td>
        <td>无数据</td>
      </tr>
      <tr v-else>
        <td>学业成绩（A2）A2=(平均绩点+5)*10</td>
        <td>学业成绩</td>
        <td>{{ this.messageObject["20240327141811"][0].name }}</td>
        <td>{{ this.messageObject["20240327141811"][0].score }}</td>
        <td>{{ totalA2 }}</td>
      </tr>

      <tr v-if="!messageObject['20240327141812'] || messageObject['20240327141812'].length === 0">
        <td :rowspan="calculateRowspan(['20240327141812', '20240327141813'])">身心素质（A3）<br/>A3=基础分+加分项-减分项</td>
        <td>身心素质加分项</td>
        <td>无数据</td>
        <td>0</td>
        <td :rowspan="calculateRowspan(['20240327141812', '20240327141813'])">{{ totalA3 }}<br/>(基础30)</td>
      </tr>
      <tr v-else>
        <td :rowspan="calculateRowspan(['20240327141812', '20240327141813'])">身心素质（A3）<br/>A3=基础分+加分项-减分项</td>
        <td :rowspan="this.messageObject['20240327141812'].length || 1">身心素质加分项</td>
        <td v-if="this.messageObject['20240327141812'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141812'][0].photoUrl)">
          {{ this.messageObject["20240327141812"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141812"][0].name }}</td>
        <td>{{ this.messageObject["20240327141812"][0].score }}</td>
        <td :rowspan="calculateRowspan(['20240327141812', '20240327141813'])">{{ totalA3 }}<br/> (基础30)</td>
      </tr>
      <tr v-if="messageObject['20240327141812'].length > 1" v-for="(award, index) in messageObject['20240327141812'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>
      <tr v-if="!messageObject['20240327141813'] || messageObject['20240327141813'].length === 0">
        <td>身心素质减分项</td>
        <td>无数据</td>
        <td>0</td>
      </tr>
      <tr v-else>
        <td :rowspan="this.messageObject['20240327141813'].length || 1">行为规范减分项</td>
        <td v-if="this.messageObject['20240327141813'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141813'][0].photoUrl)">
          {{ this.messageObject["20240327141813"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141813"][0].name }}</td>
        <td>{{this.messageObject["20240327141813"][0].score}}</td> <!-- 只打印第一个元素 -->
      </tr>
      <tr v-if="messageObject['20240327141813'].length > 1" v-for="(award, index) in messageObject['20240327141813'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>

      <tr v-if="!messageObject['20240327141815'] || messageObject['20240327141815'].length === 0">
        <td :rowspan="calculateRowspan(['20240327141815', '20240327141817'])">社会工作与对外交流（B1）<br/> B1=社会工作加分项+对外交流加分项</td>
        <td>社会工作加分项</td>
        <td>无数据</td>
        <td>0</td>
        <td :rowspan="calculateRowspan(['20240327141815', '20240327141817'])">{{ totalB1 }}<br/> (最高25)</td>
      </tr>
      <tr v-else>
        <td :rowspan="calculateRowspan(['20240327141815', '20240327141817'])">社会工作与对外交流（B1）<br/> B1=社会工作加分项+对外交流加分项</td>
        <td :rowspan="this.messageObject['20240327141815'].length || 1">社会工作加分项</td>
        <td v-if="this.messageObject['20240327141815'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141815'][0].photoUrl)">
          {{ this.messageObject["20240327141815"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141815"][0].name }}</td>
        <td>{{this.messageObject["20240327141815"][0].score}}</td> <!-- 只打印第一个元素 -->
        <td :rowspan="calculateRowspan(['20240327141815', '20240327141817'])">{{ totalB1 }}<br/> (最高25)</td>
      </tr>
      <tr v-if="messageObject['20240327141815'].length > 1" v-for="(award, index) in messageObject['20240327141815'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>

      <!-- 对外交流加分项 -->
      <tr v-if="!messageObject['20240327141817'] || messageObject['20240327141817'].length === 0">
        <td>对外交流加分项</td>
        <td>无数据</td>
        <td>0</td>
      </tr>
      <tr v-else>
        <td :rowspan="this.messageObject['20240327141817'].length || 1">对外交流加分项</td>
        <td v-if="this.messageObject['20240327141817'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141817'][0].photoUrl)">
          {{ this.messageObject["20240327141817"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141817"][0].name }}</td>
        <td>{{this.messageObject["20240327141817"][0].score}}</td> <!-- 只打印第一个元素 -->
      </tr>
      <tr v-if="messageObject['20240327141817'].length > 1" v-for="(award, index) in messageObject['20240327141817'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>

      <tr v-if="!messageObject['20240327141819'] || messageObject['20240327141819'].length === 0">
        <td :rowspan="calculateRowspan(['20240327141819', '20240327141820'])">公益服务与社会实践（B2）<br/>B2=公益服务加分项+社会实践加分项</td>
        <td>公益服务加分项</td>
        <td>无数据</td>
        <td>0</td>
        <td :rowspan="calculateRowspan(['20240327141819', '20240327141820'])">{{ totalB2 }}<br/> (最高25)</td>
      </tr>
      <tr v-else>
        <td :rowspan="calculateRowspan(['20240327141819', '20240327141820'])">公益服务与社会实践（B2）<br/>B2=公益服务加分项+社会实践加分项</td>
        <td :rowspan="this.messageObject['20240327141819'].length || 1">公益服务加分项</td>
        <td v-if="this.messageObject['20240327141819'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141819'][0].photoUrl)">
          {{ this.messageObject["20240327141819"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141819"][0].name }}</td>
        <td>{{this.messageObject["20240327141819"][0].score}}</td> <!-- 只打印第一个元素 -->
        <td :rowspan="calculateRowspan(['20240327141819', '20240327141820'])">{{ totalB2 }}<br/> (最高25)</td>
      </tr>
      <tr v-if="messageObject['20240327141819'].length > 1" v-for="(award, index) in messageObject['20240327141819'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>

      <!-- 社会实践加分项 -->
      <tr v-if="!messageObject['20240327141820'] || messageObject['20240327141820'].length === 0">
        <td>社会实践加分项</td>
        <td>无数据</td>
        <td>0</td>
      </tr>
      <tr v-else>
        <td :rowspan="this.messageObject['20240327141820'].length || 1">社会实践加分项</td>
        <td v-if="this.messageObject['20240327141820'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141820'][0].photoUrl)">
          {{ this.messageObject["20240327141820"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141820"][0].name }}</td>
        <td>{{this.messageObject["20240327141820"][0].score}}</td> <!-- 只打印第一个元素 -->
      </tr>
      <tr v-if="messageObject['20240327141820'].length > 1" v-for="(award, index) in messageObject['20240327141820'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>


      <tr v-if="!messageObject['20240327141821'] || messageObject['20240327141821'].length === 0">
        <td :rowspan="calculateRowspan(['20240327141821'])">文体艺活动（B3）</td>
        <td>文体艺活动加分项</td>
        <td>无数据</td>
        <td>0</td>
        <td :rowspan="calculateRowspan(['20240327141821'])">{{ totalB3 }}<br/> (最高25)</td>
      </tr>
      <tr v-else>
        <td :rowspan="calculateRowspan(['20240327141821'])">文体艺活动（B3）</td>
        <td :rowspan="this.messageObject['20240327141821'].length || 1">文体艺活动加分项</td>
        <td v-if="this.messageObject['20240327141821'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141821'][0].photoUrl)">
          {{ this.messageObject["20240327141821"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141821"][0].name }}</td>
        <td>{{this.messageObject["20240327141821"][0].score}}</td> <!-- 只打印第一个元素 -->
        <td :rowspan="calculateRowspan(['20240327141821'])">{{ totalB3 }}<br/> (最高25)</td>
      </tr>
      <tr v-if="messageObject['20240327141821'].length > 1" v-for="(award, index) in messageObject['20240327141821'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>

      <tr v-if="!messageObject['20240327141822'] || messageObject['20240327141822'].length === 0">
        <td :rowspan="calculateRowspan(['20240327141822', '20240327141824', '20240327141825', '20240327141828'])">学术与创新创业（B4）<br/> B4=学科竞赛加分项+专业技能及职业资格证书加分项+创新创业大赛加分项+学术与科研加分项</td>
        <td>学科竞赛加分项</td>
        <td>无数据</td>
        <td>0</td>
        <td :rowspan="calculateRowspan(['20240327141822', '20240327141824', '20240327141825', '20240327141828'])">{{ totalB4 }}<br/> (最高25)</td>
      </tr>
      <tr v-else>
        <td :rowspan="calculateRowspan(['20240327141822', '20240327141824', '20240327141825', '20240327141828'])">学术与创新创业（B4）<br/> B4=学科竞赛加分项+专业技能及职业资格证书加分项+创新创业大赛加分项+学术与科研加分项</td>
        <td :rowspan="this.messageObject['20240327141822'].length || 1">学科竞赛加分项</td>
        <td v-if="this.messageObject['20240327141822'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141822'][0].photoUrl)">
          {{ this.messageObject["20240327141822"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141822"][0].name }}</td>
        <td>{{this.messageObject["20240327141822"][0].score}}</td> <!-- 只打印第一个元素 -->
        <td :rowspan="calculateRowspan(['20240327141822', '20240327141824', '20240327141825', '20240327141828'])">{{ totalB4 }}<br/> (最高25)</td>
      </tr>
      <tr v-if="messageObject['20240327141822'].length > 1" v-for="(award, index) in messageObject['20240327141822'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>

      <!-- 专业技能及职业资格证书加分项 -->
      <tr v-if="!messageObject['20240327141824'] || messageObject['20240327141824'].length === 0">
        <td>专业技能及职业资格证书加分项</td>
        <td>无数据</td>
        <td>0</td>
      </tr>
      <tr v-else>
        <td :rowspan="this.messageObject['20240327141824'].length || 1">专业技能及职业资格证书加分项</td>
        <td v-if="this.messageObject['20240327141824'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141824'][0].photoUrl)">
          {{ this.messageObject["20240327141824"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141824"][0].name }}</td>
        <td>{{this.messageObject["20240327141824"][0].score}}</td> <!-- 只打印第一个元素 -->
      </tr>
      <tr v-if="messageObject['20240327141824'].length > 1" v-for="(award, index) in messageObject['20240327141824'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>
      <!-- 创新创业大赛加分项 -->
      <tr v-if="!messageObject['20240327141825'] || messageObject['20240327141825'].length === 0">
        <td>创新创业大赛加分项</td>
        <td>无数据</td>
        <td>0</td>
      </tr>
      <tr v-else>
        <td :rowspan="this.messageObject['20240327141825'].length || 1">创新创业大赛加分项</td>
        <td v-if="this.messageObject['20240327141825'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141825'][0].photoUrl)">
          {{ this.messageObject["20240327141825"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141825"][0].name }}</td>
        <td>{{this.messageObject["20240327141825"][0].score}}</td> <!-- 只打印第一个元素 -->
      </tr>
      <tr v-if="messageObject['20240327141825'].length > 1" v-for="(award, index) in messageObject['20240327141825'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>
      <!-- 学术与科研加分项 -->
      <tr v-if="!messageObject['20240327141828'] || messageObject['20240327141828'].length === 0">
        <td>学术与科研加分项</td>
        <td>无数据</td>
        <td>0</td>
      </tr>
      <tr v-else>
        <td :rowspan="this.messageObject['20240327141828'].length || 1">学术与科研加分项</td>
        <td v-if="this.messageObject['20240327141828'][0].photoUrl" class="link-text" @click="previewImage(this.messageObject['20240327141828'][0].photoUrl)">
          {{ this.messageObject["20240327141828"][0].name }}</td> <!-- 只打印第一个元素 -->
        <td v-else>{{ this.messageObject["20240327141828"][0].name }}</td>
        <td>{{this.messageObject["20240327141828"][0].score}}</td> <!-- 只打印第一个元素 -->
      </tr>
      <tr v-if="messageObject['20240327141828'].length > 1" v-for="(award, index) in messageObject['20240327141828'].slice(1)" :key="index">
        <td v-if="award.photoUrl" class="link-text" @click="previewImage(award.photoUrl)">{{ award.name }}<!--加分项目名称 --></td>
        <td v-else>{{ award.name }}</td>
        <td>{{ award.score }}<!--加分分数 --></td>
      </tr>
      </tbody>
    </table>
    <div style="text-align: center">
      <el-button :disabled="this.confirmClick" size="default" type="primary"
                 v-if="this.$store.state.complexUpload||this.$store.state.complexUpdate"
                 @click="confirmComplex()">提交
      </el-button>
      <el-button
          v-if="this.message.length!==0&&!this.$store.state.complexUpload||this.message.length!==0&&!this.$store.state.complexUpdate"
          icon="download" type="primary" size="default" @click="exportPic()">导出
      </el-button>
    </div>
  </div>
  <el-image-viewer v-if="imgViewerVisible" :onClose="closeViewer" :url-list="this.urlList"/>
  <h1 style="text-align: center" v-if="this.message.length===0">无数据，请先上传</h1>
</template>

<script>
import request from "@/util/request.js";
import {year} from "../../public/static/config.js";
import printJS from "print-js";
export default {
  name: "Complex",
  components: {
  },
  data(){
    return{
      imgViewerVisible: false, // 图片
      year: year,
      accountNo:JSON.parse(localStorage.getItem('user')).accountNo,
      message:[],
      userName: "",
      messageObject:{
        20240327141803:[],  // 政治素养加分项
        20240327141805:[],  // 政治素养减分项
        20240327141807:[],  // 行为规范加分项
        20240327141809:[],  // 行为规范减分项
        20240327141811:[],  // 学业成绩
        20240327141812:[],  // 身心素质加分项
        20240327141813:[],  // 身心素质减分项
        20240327141815:[],  // 社会工作加分项
        20240327141817:[],  // 对外交流加分项
        20240327141819:[],  // 公益服务加分项
        20240327141820:[],  // 社会实践加分项
        20240327141821:[],  // 加分项
        20240327141822:[],  // 学科竞赛加分项
        20240327141824:[],  // 专业技能及职业资格证书加分项
        20240327141825:[],  // 创新创业大赛加分项
        20240327141828:[],  // 学术与科研加分项
      },
      allScore: {
        year: year,
        accountNo: JSON.parse(localStorage.getItem('user')).accountNo,
        scoreAll: 0
      },
      loading: false,
      urlList: [],
      confirmClick: false
    }
  },
  created() {
    if (this.$store.state.complexUpdate) {
      this.accountNo = this.$store.state.accountNo
      console.log("综测审批中的整体查看")
      this.allScore.accountNo = this.$store.state.accountNo
      this.message = this.$store.state.complexContent
      this.message.forEach(item => {
        const typeNo = item.complexTypeNo;
        if (item.score !== 0) {
          this.messageObject[typeNo].push(item);
        }
      });
      this.loading = true;
    } else if (this.$store.state.complexUpload) {
      console.log("综测上传页面的、暂存及整体查看")
      this.accountNo = this.$store.state.accountNo
      this.allScore.accountNo = this.$store.state.accountNo
      this.year = this.$store.state.year
      this.message = this.$store.state.complexContent
      this.message.forEach(item => {
        const typeNo = item.complexTypeNo;
        if (item.score !== 0) {
          this.messageObject[typeNo].push(item);
        }
      });
      this.loading = true;
    } else if (this.$store.state.complexDetail) {
      console.log("综测成绩查看->查看详情")
      this.accountNo = this.$store.state.accountNo
      this.allScore.accountNo = this.$store.state.accountNo
      this.year = this.$store.state.year
      request.get(`/complex_related/getOne?accountNo=${this.accountNo}` + "&year=" + this.year).then(res => {
        let data = res.data.data.contentList;
        this.message = data;
        this.message.forEach(item => {
          const typeNo = item.complexTypeNo;
          if (item.score !== 0) {
            this.messageObject[typeNo].push(item);
          }
        });
        this.loading = true;
      });
    } else {
      console.log("个人综测查看")
      // 年份为最新
      const accountNo = JSON.parse(localStorage.getItem('user')).accountNo
      request.get(`/complex_related/getOne?accountNo=${accountNo}` + "&year=" + this.year).then(res => {
        if (res.data.data !== undefined) {
          let data = res.data.data.contentList;
          this.message = data;
          this.message.forEach(item => {
            const typeNo = item.complexTypeNo;
            if (item.score !== 0) {
              this.messageObject[typeNo].push(item);
            }
          });
          this.loading = true;
        }
      });
    }
    console.log(this.messageObject)
    this.getUserInfo()
  },
  computed: {
    totalA1() {
      let total = 0;
      // 遍历政治素养加分项
      if (this.messageObject['20240327141803'].length > 0) {
        this.messageObject['20240327141803'].forEach(item => {
          total += parseFloat(item.score);
        });
      }
      // 遍历政治素养减分项
      if (this.messageObject['20240327141805'].length > 0) {
        this.messageObject['20240327141805'].forEach(item => {
          total -= parseFloat(item.score);
        });
      }
      // 遍历行为规范加分项
      if (this.messageObject['20240327141807'].length > 0) {
        this.messageObject['20240327141807'].forEach(item => {
          total += parseFloat(item.score);
        });
      }
      // 遍历行为规范减分项
      if (this.messageObject['20240327141809'].length > 0) {
        this.messageObject['20240327141809'].forEach(item => {
          total -= parseFloat(item.score);
        });
      }
      let a1 = Math.min(total + 30, 50)
      this.allScore.scoreA1 = a1
      return a1; // 限制总数不超过50
    },

    totalA2() {
      // 平均绩点
      let a2 = parseFloat(this.messageObject["20240327141811"].at(0).score);
      this.allScore.scoreA2 = a2
      return a2
    },
    totalA3() {
      let total = 0;

      const addItems = this.messageObject['20240327141812'] || [];
      for (let i = 0; i < addItems.length; i++) {
        total += parseFloat(addItems[i]?.score) || 0;
      }
      const subtractItems = this.messageObject['20240327141813'] || [];
      subtractItems.forEach(item => {
        total -= parseFloat(item?.score) || 0;
      });
      let a3 = Math.min(total + 30, 50);
      this.allScore.scoreA3 = a3
      return a3; // 限制总数不超过50
    },

    totalB1() {
      let total = 0;
      // 遍历社会工作加分项
      if (this.messageObject['20240327141815'].length > 0) {
        this.messageObject['20240327141815'].forEach(item => {
          total += parseFloat(item.score);
        });
      }
      // 遍历对外交流加分项
      if (this.messageObject['20240327141817'].length > 0) {
        this.messageObject['20240327141817'].forEach(item => {
          total += parseFloat(item.score);
        });
      }
      let b1 = Math.min(total, 25)
      this.allScore.scoreB1 = b1
      return b1; // 限制总数不超过25
    },
    totalB2() {
      let total = 0;
      // 遍历公益服务加分项
      if (this.messageObject['20240327141819'].length > 0) {
        this.messageObject['20240327141819'].forEach(item => {
          total += parseFloat(item.score);
        });
      }
      // 遍历社会实践加分项
      if (this.messageObject['20240327141820'].length > 0) {
        this.messageObject['20240327141820'].forEach(item => {
          total += parseFloat(item.score);
        });
      }
      let b2 = Math.min(total, 25)
      this.allScore.scoreB2 = b2
      return b2; // 限制总数不超过25
    },
    totalB3() {
      let total = 0;
      // 遍历文体艺活动加分项
      if (this.messageObject['20240327141821'].length > 0) {
        this.messageObject['20240327141821'].forEach(item => {
          total += parseFloat(item.score);
        });
      }
      let b3 = Math.min(total, 25)
      this.allScore.scoreB3 = b3
      return b3; // 限制总数不超过25
    },
    totalB4() {
      let total = 0;
      if (this.messageObject['20240327141822'].length > 0) {
        this.messageObject['20240327141822'].forEach(item => {
          total += parseFloat(item.score);
        });
      }
      if (this.messageObject['20240327141824'].length > 0) {
        this.messageObject['20240327141824'].forEach(item => {
          total += parseFloat(item.score);
        });
      }
      if (this.messageObject['20240327141825'].length > 0) {
        this.messageObject['20240327141825'].forEach(item => {
          total += parseFloat(item.score);
        });
      }
      if (this.messageObject['20240327141828'].length > 0) {
        this.messageObject['20240327141828'].forEach(item => {
          total += parseFloat(item.score);
        });
      }
      let b4 = Math.min(total, 25)
      this.allScore.scoreB4 = b4
      return b4; // 限制总数不超过25
    }
  },

  methods:{
    //导出图片
    exportPic: function () {
      printJS({
        printable: "pdf", type: 'html', style: `@page {width: 100%}
        tbody {
          text-align: center;
        }
        table {
             border-collapse: collapse;
        }
        body {zoom: 88%;}`,
        targetStyles: ['*']
      });
    },
    // 图片预览
    previewImage(src) {
      // 这里可以根据你的需求实现图片预览功能，比如弹出模态框等
      this.urlList.push(src)
      this.imgViewerVisible = true
    },
    closeViewer() {
      if (this.imgViewerVisible) {
        this.imgViewerVisible = false
        this.urlList.pop();
      }
    },
    confirmComplex() {
      this.confirmClick = true
      let content = "[";
      this.message.forEach((item, index) => {
        if (item.score > 0) {
          item = JSON.stringify(item)
          content += item
          if (index !== this.message.length - 1) {
            content += ","
          }
        }
      })
      content += "]"
      let result = {
        accountNo: this.accountNo,
        year: this.year,
        content: content,
        state: '0'
      }
      this.allScore.scoreAll = this.allScore.scoreA1 + this.allScore.scoreA2 + this.allScore.scoreA3 + this.allScore.scoreB1 +
          this.allScore.scoreB2 + this.allScore.scoreB3 + this.allScore.scoreB4
      // 提交数据
      request.post("/complex_related/edit", result).then(() => {
        request.post("/info_complex/edit", this.allScore)
        this.$alert('提交成功', '提交成功', {
          confirmButtonText: '确定',
          showClose: false, //是否显示右上角的x
        }).then(() => {
          // 综测审批过程中提交不进行跳转、老师修改学生不跳转
          if (!this.$store.state.complexUpdate && !this.$store.state.changeComplex) {
            this.$router.push("/complex")
          }
          this.$store.commit('complexUpdateSetFalse')
          this.$store.commit('complexUploadSetFalse')
          this.$store.commit('setChangeComplexFalse')
        });
      })
      this.confirmClick = false
    },
    calculateRowspan(keys) {
      let rowspan = 0;
      keys.forEach(key => {
        rowspan += this.messageObject[key].length > 0 ? this.messageObject[key].length : 1;
      });
      return rowspan;
    },
    getUserInfo(){
      request.get("/info_account/getNameByAccountNo?accountNo=" + this.accountNo).then(res => {
        this.userName = res.data.data
      })
    },
  }
}

</script>


<style>
table {
  border-collapse: collapse;
  text-align: center;
  vertical-align: middle;
  font-family: "宋体", Si,mSun;
}
.link-text {
  color: blue;
  text-decoration: underline;
  cursor: pointer;
}

th, td {
  border: 1px solid black;
  padding: 10px 0;
  font-family: "Times New Roman", Times, serif;
}
</style>
<script setup>
</script>
